package com.shoesmail.controller;

import com.shoesmail.utils.MinioUtil;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;

/**
 * @author ：CDB
 * @description：测试minIO
 * @date ：2025/9/17 21:15
 */
@RestController
@RequestMapping("/test")
public class MinioTestController {
    private final MinioUtil minioUtils;

    public MinioTestController(MinioUtil minioUtils) {
        this.minioUtils = minioUtils;
    }

    @PostMapping("/upload")
    public String upload(@RequestParam("file") MultipartFile file,String fileName) throws Exception {
        try (InputStream stream = file.getInputStream()) {
            minioUtils.upload(fileName, stream, file.getContentType());
        }
        return "上传成功: " + fileName;
    }

    @GetMapping("/url/{fileName}")
    public String getFileUrl(@PathVariable String fileName) throws Exception {
        return minioUtils.getPhotoUrl(fileName);
    }
}
